<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-row :gutter="10">
      <el-col :span="22"
        ><el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
          label-width="68px"
        >
          <el-form-item prop="name" label-width="0">
            <el-input
              v-model="queryParams.subject"
              placeholder="请输入主题名称"
              clearable
              prefix-icon="el-icon-search"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <span class="close_btn" @click="handleQuery">查询</span>
            <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        > -->
          </el-form-item>
        </el-form></el-col
      ><el-col :span="2">
        <span class="close_btn addInvitationStyle" @click="handleAdd"
          >发起邀约</span
        ></el-col
      ></el-row
    >

    <!-- 操作工具栏 -->
    <!-- <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >发起邀约</el-button
        >
      </el-col>
    </el-row> -->

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <el-table-column label="序号" align="center"
        ><template slot-scope="scope">
          {{ Number(scope.$index + 1) }}
        </template>
      </el-table-column>
      <el-table-column prop="subject" label="主题" align="center">
        <template slot-scope="scope">
          {{ scope.row.subject || "-" }}
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="发起时间" align="center">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) || "-" }}
        </template>
      </el-table-column>
      <el-table-column prop="type" label="类型" align="center">
        <template slot-scope="scope">
          {{ scope.row.ruleType == 1 ? "随机抽取" : "定向选择" || "-" }}
        </template>
      </el-table-column>
      <el-table-column prop="status" label="邀约状态" align="center">
        <template slot-scope="scope">
          {{
            scope.row.status == 0
              ? "待开启"
              : scope.row.status == 1
              ? "进行中"
              : "已完成"
          }}
        </template>
      </el-table-column>
      <el-table-column prop="rosterStatus" label="名单状态" align="center">
        <template slot-scope="scope">
          {{ scope.row.rosterStatus == 1 ? "已确认" : "待确认" }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template v-slot="scope">
          <el-button
            v-if="scope.row.status == 0"
            size="mini"
            type="text"
            icon="el-icon-video-play"
            @click="handleStart(scope.row.id)"
            >开启</el-button
          >
          <el-button
            v-else
            type="text"
            size="mini"
            icon="el-icon-video-play"
            style="color: gray"
            disabled
            >开启</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleDetail(scope.row)"
            >详情</el-button
          >
          <el-button
            v-if="scope.row.status == 1"
            size="mini"
            type="text"
            icon="el-icon-delete"
            style="color: gray"
            disabled
            >删除</el-button
          >
          <el-button
            v-else
            size="mini"
            type="text"
            icon="el-icon-delete"
            style="color: red"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      class="hy_page"
      v-show="total > 0"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryParams.pageNo"
      :page-size="queryParams.pageSize"
      layout="total, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <!-- 开启弹出框 -->
    <startDialog
      ref="startDialog"
      :id="editId"
      @startInvitation="startInvitation"
    />
    <!-- 删除二次确认弹框 -->
    <el-dialog :visible.sync="deleteDialogVisible" width="30%" title="提示">
      <div class="dialog_body_div">
        <span>是否确认删除该邀约</span>
      </div>
      <span slot="footer" class="dialog-footer">
        <span
          @click="deleteDialogVisible = false"
          class="close_btn"
          style="margin-right: 12px"
          >取消</span
        >
        <span @click="submitDelete" class="close_btn addInvitationStyle"
          >确定</span
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getInvitationList,
  deleteExpertInvitation,
} from "@/api/enterprise/invitation";
import startDialog from "./startDialog/index.vue";
export default {
  name: "expertInvitation",
  components: { startDialog },
  data() {
    return {
      //当前编辑id
      editId: "0",
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 工作流的列表
      list: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        subject: null,
      },
      deleteDialogVisible: false,
      editId: "",
    };
  },
  created() {
    this.getList();
  },
  methods: {
    //开启邀约后的状态调整
    startInvitation(val) {
      // this.list = this.list.map((item) => {
      //   item.isStart = item.id == this.editId ? val : false;
      //   return item;
      // });
      // console.log(this.list);
      this.getList();
    },
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.queryParams.pageNo = val;
      this.getList();
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getInvitationList(this.queryParams).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNo: 1,
        pageSize: 10,
        subject: null,
      };
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 详情按钮操作 */
    handleDetail(row) {
      this.$router.push({
        path: "/expert/invitation/detail",
        query: {
          id: row.id,
          status: row.status, //邀约状态
          rosterStatus: row.rosterStatus, //名单状态
          ruleType: row.ruleType, //选择模式
        },
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/expert/invitation/add",
      });
    },
    /** 开启按钮操作 */
    handleStart(id) {
      this.editId = String(id);
      this.$refs.startDialog.show();
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.editId = row.id;
      this.deleteDialogVisible = true;
      // this.$modal
      //   .confirm("是否确认删除该邀约?", "提示")
      //   .then(function () {
      //     return deleteExpertInvitation(id);
      //   })
      //   .then(() => {
      //     this.getList();
      //     this.$modal.msgSuccess("删除成功");
      //   })
      //   .catch(() => {});
    },
    submitDelete() {
      deleteExpertInvitation(this.editId).then((res) => {
        this.deleteDialogVisible = false;
        this.getList();
        this.$message.success("删除成功");
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.hy_page {
  float: right;
  margin-top: 20px;
}
.addInvitationStyle {
  color: #ffffff;
  background: #4877ee;
}
::v-deep .el-dialog__body {
  padding-top: 0 !important;
}
::v-deep .el-dialog__title {
  font-weight: bold;
}
</style>
<style>
.close_btn {
  display: inline-block;
  cursor: pointer;
  width: 82px;
  height: 32px;
  line-height: 32px;
  text-align: center;
  border-radius: 3px;
  font-size: 14px;
  font-family: SourceHanSansCN-Medium, SourceHanSansCN;
  font-weight: 500;
  color: #4877ee;
  border: 1px solid #4877ee;
}
</style>
